@extends('admin.common.form')
@section('title', '列表示例')

@section('head')
    <style>
        .layuimini-upload {
            position: relative;
        }
        .layuimini-upload .layuimini-upload-btn {
            display: inline-block;
            position: absolute;
            right: 0px;
            background-color: #fff;
        }
        .layuimini-upload-show {
            margin-top: 10px;
            margin-bottom: 0;
        }
        .layuimini-upload-show li {
            position: relative;
            display: inline-block;
            padding: 5px 0 5px 0;
            padding-left: 10px;
            padding-right: 10px;
            border: 1px solid #e2e2e2;
        }
        .layuimini-upload-show a img {
            height: 80px;
            object-fit: cover;
        }
        .layuimini-upload-show .uploads-delete-tip {
            position: absolute;
            right: 10px;
            font-size: 12px;
        }
        .badge {
            display: inline-block;
            min-width: 10px;
            padding: 3px 7px;
            font-size: 11px;
            font-weight: bold;
            color: #fff;
            line-height: 1;
            vertical-align: middle;
            white-space: nowrap;
            text-align: center;
            background-color: #777777;
            border-radius: 10px;
        }
        .bg-red {
            background-color: #e74c3c !important;
        }
    </style>
@endsection

@section('search')
@endsection

@section('content')

    <div class="layui-form-item">
        <label class="layui-form-label">验证必填项</label>
        <div class="layui-input-block">
            <input type="text" name="username" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">日期</label>
        <div class="layui-input-block">
            <input type="text" name="date" id="date" lay-verify="datetime" placeholder="yyyy-MM-dd HH-ii-ss" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">自定义验证</label>
        <div class="layui-input-block layui-input-wrap">
            <input type="password" name="password" lay-verify="required|pass" placeholder="请输入" autocomplete="off" lay-affix="eye" class="layui-input">
            <tip>6 到 12 位字符</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">数字输入框</label>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="number" name="price_min" placeholder="" autocomplete="off" class="layui-input" min="0" step="1" lay-affix="number">
            </div>
            <div class="layui-form-mid">-</div>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="number" name="price_max" placeholder="" autocomplete="off" class="layui-input" min="0" step="1" lay-affix="number">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">单行选择框</label>
        <div class="layui-input-block">
            <select name="interest" lay-filter="aihao">
                <option value=""></option>
                <option value="0">写作</option>
                <option value="1" selected>阅读</option>
                <option value="2">游戏</option>
                <option value="3">音乐</option>
                <option value="4">旅行</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">xm-select</label>
        <div class="layui-input-block">
            <div class="xm-select-demo" id="demo1"></div>
            <tip>文档地址: https://cdn.faysunshine.com/file/xm-select/v1.2.4/index.html</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">分组选择框</label>
            <div class="layui-input-inline">
                <select name="quiz">
                    <option value="">请选择问题</option>
                    <optgroup label="城市记忆">
                        <option value="你工作的第一个城市">你工作的第一个城市</option>
                    </optgroup>
                    <optgroup label="学生时代">
                        <option value="你的工号">你的工号</option>
                        <option value="你最喜欢的老师">你最喜欢的老师</option>
                    </optgroup>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">搜索选择框</label>
            <div class="layui-input-inline">
                <select name="modules" lay-verify="required" lay-search>
                    <option value="">直接选择或搜索选择</option>
                    <option value="1">layer</option>
                    <option value="2">form</option>
                    <option value="3">layim</option>
                    <option value="4">element</option>
                    <option value="5">laytpl</option>
                    <option value="6">upload</option>
                    <option value="7">laydate</option>
                    <option value="8">laypage</option>
                    <option value="9">flow</option>
                    <option value="10">util</option>
                    <option value="11">code</option>
                    <option value="12">tree</option>
                    <option value="13">layedit</option>
                    <option value="14">nav</option>
                    <option value="15">tab</option>
                    <option value="16">table</option>
                    <option value="17">select</option>
                    <option value="18">checkbox</option>
                    <option value="19">switch</option>
                    <option value="20">radio</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联动选择框</label>
        <div class="layui-input-inline">
            <select name="quiz1">
                <option value="">请选择省</option>
                <option value="浙江" selected>浙江省</option>
                <option value="你的工号">江西省</option>
                <option value="你最喜欢的老师">福建省</option>
            </select>
        </div>
        <div class="layui-input-inline">
            <select name="quiz2">
                <option value="">请选择市</option>
                <option value="杭州">杭州</option>
                <option value="宁波" disabled>宁波</option>
                <option value="温州">温州</option>
                <option value="温州">台州</option>
                <option value="温州">绍兴</option>
            </select>
        </div>
        <div class="layui-input-inline">
            <select name="quiz3">
                <option value="">请选择县/区</option>
                <option value="西湖区">西湖区</option>
                <option value="余杭区">余杭区</option>
                <option value="拱墅区">临安市</option>
            </select>
        </div>
        <div class="layui-form-mid layui-text-em">
            <i class="layui-icon layui-icon-tips" lay-tips="此处只是演示联动排版，并未做联动交互"></i>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">复选框</label>
        <div class="layui-input-block">
            <input type="checkbox" name="arr[0]" title="选项1">
            <input type="checkbox" name="arr[1]" title="选项2" checked>
            <input type="checkbox" name="arr[2]" title="选项3">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">开关</label>
        <div class="layui-input-block">
            <input type="checkbox" name="open" lay-skin="switch" lay-filter="switchTest" title="ON|OFF">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">单选框</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="男" title="男" checked>
            <input type="radio" name="sex" value="女" title="女">
            <input type="radio" name="sex" value="禁" title="禁用" disabled>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">普通文本域</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>

    {{--todo: 上传管理 --}}
    <div class="layui-form-item">
        <label class="layui-form-label required">多图</label>
        <div class="layui-input-block layuimini-upload">
            <input name="images" class="layui-input layui-col-xs6" lay-verify="required" placeholder="请上传商品图片" value="">
            <div class="layuimini-upload-btn">
                <span><a class="layui-btn" data-upload="images" data-upload-number="more" data-upload-exts="png|jpg|ico|jpeg" data-upload-icon="image"><i class="fa fa-upload"></i> 上传</a></span>
                <span><a class="layui-btn layui-btn-normal" id="select_images" data-upload-select="images" data-upload-number="more" data-upload-mimetype="image/*"><i class="fa fa-list"></i> 选择</a></span>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">单图</label>
        <div class="layui-input-block layuimini-upload">
            <input name="logo" class="layui-input layui-col-xs6" lay-verify="required" placeholder="请上传分类图片" value="">
            <div class="layuimini-upload-btn">
                <span><a class="layui-btn" data-upload="logo" data-upload-number="one" data-upload-exts="png|jpg|ico|jpeg" data-upload-icon="image"><i class="fa fa-upload"></i> 上传</a></span>
                <span><a class="layui-btn layui-btn-normal" id="select_logo" data-upload-select="logo" data-upload-number="one" data-upload-mimetype="image/*"><i class="fa fa-list"></i> 选择</a></span>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">富文本编辑器</label>
        <div class="layui-input-block">
            <div class="editor-border">
                <div class='wangEditor_div'>  {{--边框--}}
                    <textarea name='content' rows='20' class='layui-textarea editor layui-hide'>这里是默认内容</textarea> {{--内容--}}
                    <div id='editor_toolbar_content'></div>{{--工具栏--}}
                    <div id='editor_content' style='height: 300px'></div>{{--内容区域--}}
                </div>
            </div>
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认">
    </div>

@endsection

@section('foot')
{{--    <script src="https://unpkg.com/@wangeditor/editor@latest/dist/index.js"></script>--}}
    <script src="/static/js/lib/wang-editor-v5.1.23/wang-editor.js"></script>
    <script src="/static/js/lib/xm-select-v1.2.4/xm-select.js"></script>
    <script>
        layui.config({
            base: '/static/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index', //主入口模块
            tools: 'tools'
        }).use(['index', 'table', 'tools'], function(){
            var $ = layui.jquery,
                form = layui.form,
                laydate = layui.laydate,
                tools = layui.tools;


            // xm-select 示例
            var demo1 = xmSelect.render({
                el: '#demo1',
                paging: true, // 开启分页
                pageSize: 2, // 每页显示数量
                toolbar: {show: true},
                // radio: true, // 是否单选
                clickClose: false, // 点击选项后是否关闭下拉框
                name: 'xm-select-demo1',
                prop: { // 自定义属性
                    value: 'id',
                    name: 'name',
                },
                data: [{name:'名称1', id: 1},{name:'名称2', id: 2},{name:'名称3', id: 3}],
                // 默认选中
                initValue: [2,3],
                // 远程搜索等自行查看文档
            })
            // 异步加载数据
            // $.ajax({
            //     url: '/admin/user/getUserList',
            //     type: 'post',
            //     dataType: 'json',
            //     success: function(res){
            //         console.log(res);
            //         demo1.update({
            //             data: res.data,
            //             autoRow: true,
            //         })
            //     }
            // })


            // 自定义验证规则
            form.verify({
                pass: function(value) {
                    if (!/(.+){6,12}$/.test(value)) {
                        return '密码必须 6 到 12 位';
                    }
                }
            });

            // 指定开关事件
            form.on('switch(switchTest)', function(data){
                layer.msg('开关 checked：'+ (this.checked ? 'true' : 'false'), {
                    offset: '6px'
                });
                layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是 ON|OFF', data.othis)
            });

            // 日期
            laydate.render({
                elem: '#date',
                type: 'datetime',
                format: 'yyyy-M-d HH:mm:ss'
            });

            var submitting = false;//防止重复提交
            form.on('submit(layuiadmin-app-form-submit)', function (data) {
                if (submitting) {
                    return false;
                }
                // console.log(data);
                submitting = true;
                var field = data.field; //获取提交的字段
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                field._token = "{{ csrf_token() }}"
                console.log(field);
                tools.ajax('/admin/curd/add', 'post', field, function (res) {
                    if (res.code === 0) {
                        parent.layui.table.reload('test-table-operate'); //重载表格
                        parent.layer.close(index); //执行关闭
                    }
                    submitting = false;
                })

            });
        });
    </script>
@endsection
